from pyproj import Transformer


def read():
    fileName = "data_00.txt"
    transformer = Transformer.from_crs(crs_from="EPSG:4326",crs_to="EPSG:4087")#将GPS坐标转化为平面坐标
    data = []
    with open(fileName,"r",encoding='utf-8') as f:
        for i in f.readlines():
            temp = i.split()
            if len(temp)== 4:
                data.append(i)
            elif len(temp)==8:
                begintime = temp[0]
                typeStr = temp[1]
                longitude = float(temp[2])#经度
                latitude = float(temp[3])#纬度
                radius = float(temp[4])
                capacity = temp[5]
                endtime = temp[6]
                rate = temp[7]
                tr = transformer.transform(latitude,longitude)#latitude,longitude 是纬经度，而是不是默认的经纬度
                x = tr[0]/100
                y = tr[1]/100
                tr = transformer.transform(radius,radius)
                radius = tr[0]/100
                s = begintime+" "+typeStr+" "+str(x)+" "+str(y)+" "+str(radius)+" "+capacity+" "+endtime+" "+rate+"\n"
                data.append(s)
            else:
                begintime = temp[0]
                typeStr = temp[1]
                longitude = float(temp[2])
                latitude = float(temp[3])
                endtime = temp[4]
                pay = temp[5]
                tr = transformer.transform(latitude,longitude)#latitude,longitude 是纬经度，而是不是默认的经纬度
                x = tr[0]/100
                y = tr[1]/100
                s = begintime+" "+typeStr+" "+str(x)+" "+str(y)+" "+endtime+" "+pay+"\n"
                data.append(s)
    ouputFile = "convertdata.txt"
    with open(ouputFile,"w",encoding='utf-8') as f:
        for i in data:
            f.write(i)


                



if __name__ =="__main__":
    read()